package cn.edu.xmu.tangzk.scala.s99

import P09.pack
import P10.encode

object P11 {

    def encodeModified1[A](ls: List[A]): List[Any] = {
        pack(ls) map { e =>
            e.length match {
                case 1 => e.head
                case _ => (e.length, e.head)
            }
        }
    }

    def encodeModified2[A](ls: List[A]): List[Any] = {
        encode(ls) map { t =>
            if (t._1 == 1) t._2
            else t
        }
    }

    def main(args: Array[String]) {
        println(encodeModified1(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e)))
        println(encodeModified2(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e)))
    }
}